package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.entity.info.Info;
import com.clas.liu.myapplication.model.event.EditEvent;
import com.clas.liu.myapplication.model.impl.BaseModel;
import com.clas.liu.myapplication.model.impl.EditModel;
import com.clas.liu.myapplication.presenter.i.IEditPresenter;
import com.clas.liu.myapplication.view.activity.impl.BaseActivity;
import com.clas.liu.myapplication.view.activity.impl.EditActivity;

/**
 * Created by liu on 2019/5/5.
 */

public class EditPresenter extends BasePresenter<EditActivity,EditModel> implements IEditPresenter {

    public EditPresenter(EditActivity view) {
        super(view);
    }

    @Override
    public void addInfo(Info info) {
        mModel.addInfo(info);
    }

    @Override
    public void editInfo(Info info) {
        mModel.editInfo(info);
    }

    @Override
    protected EditModel getModel(Handler handler) {
        return new EditModel(handler);
    }

    @Override
    protected void eventReceive(Message msg) {
        switch (msg.what) {
            case EditEvent.ADD_INFO_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case EditEvent.ADD_INFO_OK:
                mView.addReturn();
                break;
            case EditEvent.EDIT_INFO__FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case EditEvent.EDIT_INFO_OK:
                mView.editReturn();
                break;
        }
    }
}
